<template>
<el-form label-width="150px">
  <el-form-item label="ID">
   <div class="detail">&nbsp;{{ user.id }}</div>
  </el-form-item>

  <el-form-item label="账号">
   <div class="detail">&nbsp;{{ user.loginAct }}</div>
  </el-form-item>

  <el-form-item label="密码">
   <div class="detail">&nbsp;******</div>
  </el-form-item>

  <el-form-item label="姓名">
   <div class="detail">&nbsp;{{ user.name }}</div>
  </el-form-item>

  <el-form-item label="手机">
   <div class="detail">&nbsp;{{ user.phone }}</div>
  </el-form-item>

  <el-form-item label="邮箱">
   <div class="detail">&nbsp;{{ user.email }}</div>
  </el-form-item>

  <el-form-item label="账号是否未过期">
   <div class="detail">&nbsp;{{ user.accountNoExpired === 1 ? '是' : '否' }}</div>
  </el-form-item>

  <el-form-item label="密码是否未过期">
   <div class="detail">&nbsp;{{ user.credentialsNoExpired === 1 ? '是' : '否' }}</div>
  </el-form-item>

  <el-form-item label="账号是否未锁定">
   <div class="detail">&nbsp;{{ user.accountNoLocked === 1 ? '是' : '否' }}</div>
  </el-form-item>

  <el-form-item label="账号是否已启用">
   <div class="detail">&nbsp;{{ user.accountEnabled === 1 ? '是' : '否' }}</div>
  </el-form-item>

  <el-form-item label="创建时间">
   <div class="detail">&nbsp;{{ user.createTime }}</div>
  </el-form-item>

  <el-form-item label="创建人">
   <div class="detail">&nbsp;{{ user.createByDO.name }}</div>
  </el-form-item>

  <el-form-item label="编辑时间">
   <div class="detail">&nbsp;{{ user.editTime }}</div>
  </el-form-item>
  
  <el-form-item label="编辑人">
   <div class="detail">&nbsp;{{ user.editByDO.name }}</div>
  </el-form-item>

  <el-form-item label="最近登录时间">
   <div class="detail">&nbsp;{{ user.lastLoginTime }}</div>
  </el-form-item>

  <el-form-item>
   <el-button type="primary" @click="goBack">返 回</el-button>
  </el-form-item>
 </el-form>
</template>

<script setup>

import { ref, onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
import { doGet } from '../http/httpRequest'
import { showMessage } from '../util/message';

let user = ref({
    createByDO: {},
    editByDO: {}
})

onMounted(() => {
    loadUser()
})

//根据id查询用户详情
const loadUser = () => {
    //获取url中的id
    let id = useRoute().params.userId

    //根据id查询用户详情
    doGet('/api/user/' + id,{}).then(resp => {
        console.log(resp.data.code)
        
        if (resp.data.code == 200) {
            //将用户详情赋值给user对象
            user.value = resp.data.info

            //如果用户的创建人或编辑人为空，则创建一个空对象 不是null
            if(!resp.data.info.createByDO){
                user.value.createByDO = {}
            }
            //如果用户的编辑人为空，则创建一个空对象 不是null
            if(!resp.data.info.editByDO){
                user.value.editByDO = {}
            }
        } else {
            showMessage(resp.data.msg, 'error')
        }
    })

}
let router = useRouter()

const goBack = () => {
    //返回上一页
    router.back()
}

</script>

<style scoped>
</style>